#include <string>
#include <iostream>
#include <algorithm>
using namespace std;

class Student{
private:
	int grade;
	int cls;
	string firstName;
	string lastName;
	
	int hashCode(){
		hash<int> hash_int;
		hash<string> hash_s;
		int B = 31;
		int hash = 0;
		//int M = 11;
		hash = (hash * B + hash_int(grade));
		hash = (hash * B + hash_int(cls));
		transform(firstName.begin(),firstName.end(),firstName.begin(),::tolower);	
		transform(lastName.begin(),lastName.end(),lastName.begin(),::tolower);
		
		hash = (hash * B + hash_s(firstName));
		hash = (hash * B + hash_s(lastName));
		
		return hash;
	}
public:
	Student(int grade,int cls,string firstName,string lastName){
		this->grade = grade;
		this->cls = cls;
		this->firstName = firstName;
		this->lastName = lastName;
	}
	int hash_Public(){
		int M = 57;
		return (hashCode() & 0x7fffffff)%M;
	}
	
	bool isequals(Student *another){
		bool flag =  (hash_Public() == another->hash_Public());
		if(flag==false){
			return false;
		}else{
			// 有可能存在哈希冲突现象
			return this->grade == another->grade &&
			       this->cls == another->cls &&
				   this->firstName == another->firstName &&
				   this->lastName == another->lastName;
		}
		
	}
	
};


int main(){
	Student *student1 = new Student(3,2,"Da","Liu");
	Student *student2 = new Student(3,2,"ER","LIU");
	cout << student1->hash_Public()<<endl;
	cout << student2->hash_Public() <<endl;
	cout << student1->isequals(student2) <<endl;
	//cout << (student1->hash_Public() == student2->hash_Public()) <<endl;
	
	return 0;
}
